﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MDIDemo.Windows.Report
{
    public partial class frmBaoCaoDoanhSoTheoKhachHang : DevExpress.XtraEditors.XtraForm
    {
        Dictionary<string, object> _valueList = new Dictionary<string, object>();

        public Dictionary<string, object> ValueList
        {
            get { return _valueList; }
            set { _valueList = value; }
        }
        DataSet _ds = null;
        public DataSet DataSource { get { return _ds; } }
        public string Type
        {
            get
            {
                return "DOANHSO-KHACHHANG";
            }

        }

        public frmBaoCaoDoanhSoTheoKhachHang()
        {
            InitializeComponent();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            Close();
        }
        public DataSet BuildDataSourceDTLN()
        {
            string query = @"SELECT     GIAODICH.LOAICT, GIAODICH.MAKH, SUM(GIAODICH.TONGTIEN) as TONGTIEN, SUM(GIAODICH.TIENMAT) as TIENMAT, SUM(GIAODICH.CONGNO) as CONGNO, SUM(GIAODICH.THUNGAY) as THUNGAY, CUSTINFO.TENGD,
                       CUSTINFO.DIACHI, CUSTINFO.DIENTHOAI
FROM         GIAODICH INNER JOIN
                      CUSTINFO ON GIAODICH.MAKH = CUSTINFO.CUSTID
WHERE     (GIAODICH.NGAYCT BETWEEN '{0:yyyy-MM-dd}' AND '{1:yyyy-MM-dd}') AND (GIAODICH.LOAICT = '{2}')
GROUP BY GIAODICH.LOAICT, GIAODICH.MAKH, CUSTINFO.TENGD, CUSTINFO.DIACHI, CUSTINFO.DIENTHOAI
ORDER BY SUM(GIAODICH.TONGTIEN) DESC";

            query = string.Format(query, txtDateF.EditValue, txtDateT.EditValue, "BH001");
            BUS.CommonControl ctr = new BUS.CommonControl();
            _ds = ctr.executeSelectQueries(query);
            return _ds;
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {

            _ds = BuildDataSourceDTLN();

            if (_ds.Tables.Count == 0)
            {
                XtraMessageBox.Show("Dữ liệu không tồn tại!");
                return;
            }
            bool isdata = false;
            foreach (DataTable dt in _ds.Tables)
            {
                if (dt.Rows.Count > 0)
                {
                    isdata = true;
                    break;
                }
            }
            if (isdata == false)
            {
                XtraMessageBox.Show("Dữ liệu không tồn tại!");
                return;
            }
            _valueList.Add("FROM", txtDateF.EditValue);
            _valueList.Add("TO", txtDateT.EditValue);

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }

        private void frmBangKeGTGT_Load(object sender, EventArgs e)
        {
            txtDateF.EditValue = new DateTime(frmMain.__ngayMoSo.Year, frmMain.__ngayMoSo.Month, 1);
            txtDateT.EditValue = frmMain.__ngayMoSo;
        }


    }
}